package com.gdth.bank.presenter;

import java.util.List;

import org.greenrobot.eventbus.EventBus;

import rx.Subscriber;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

import com.gdth.bank.event.MessageEvent;
import com.gdth.bank.model.TAppBfrjJtcybModel;
import com.gdth.bank.view.TAppBfrjJtcybView;
import com.gdth.database.bean.TAppBfrjJtcyb;

public class TAppBfrjJtcybPresenter {
     private  TAppBfrjJtcybModel mTAppBfrjJtcybModel;
     private TAppBfrjJtcybView  mTAppBfrjJtcybView;
        
     public   TAppBfrjJtcybPresenter(TAppBfrjJtcybView mTAppBfrjJtcybView){
    	 this.mTAppBfrjJtcybView =mTAppBfrjJtcybView;
    	 mTAppBfrjJtcybModel= new TAppBfrjJtcybModel();
     }
       public void savejtcyxx(TAppBfrjJtcyb mTAppBfrjJtcyb ,String jcuuid,int type , boolean isHuzhu){
    	   mTAppBfrjJtcybView.showProgressDialog("保存中");
    	   mTAppBfrjJtcybModel.savejtcyxx(mTAppBfrjJtcyb,jcuuid,type,isHuzhu)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<TAppBfrjJtcyb>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
					mTAppBfrjJtcybView.hideProgressDialog();
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcybView.hideProgressDialog();
					//mTAppBfrjJtcybView.showMessage("保存失败,请检查证件号是否存在该客户");
					EventBus.getDefault().post(new MessageEvent(MessageEvent.SHOWMESSAGETOAST, "保存失败,请检查证件号是否存在该客户"));
				}

				@Override
				public void onNext(TAppBfrjJtcyb arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcybView.saveSuccess(arg0);
				}
				
			});
       }
       public void getjtcyxx(String jcuuid){
    	   mTAppBfrjJtcybModel.getjtcyxxUuid(jcuuid)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<List<TAppBfrjJtcyb>>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
				}

				@Override
				public void onNext(List<TAppBfrjJtcyb> arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcybView.getjtcyXx(arg0);
				}
				
			});
       }

	public void getbxxbZJHMM(String jtuuid){
		mTAppBfrjJtcybModel.getbxxbZJHMM(jtuuid)
				.subscribeOn(Schedulers.io())
				.unsubscribeOn(Schedulers.io())
				.observeOn(AndroidSchedulers.mainThread())
				.subscribe(new Subscriber<String>(){

					@Override
					public void onCompleted() {
						// TODO Auto-generated method stub
					}

					@Override
					public void onError(Throwable arg0) {
						// TODO Auto-generated method stub
					}

					@Override
					public void onNext(String arg0) {
						// TODO Auto-generated method stub
						mTAppBfrjJtcybView.getbxxbZjhm(arg0);
					}

				});
	}

       public void getjtcyUuid(String jtuuid){
    	   mTAppBfrjJtcybModel.getjtcyUuid(jtuuid)
			.subscribeOn(Schedulers.io())
			.unsubscribeOn(Schedulers.io())
			.observeOn(AndroidSchedulers.mainThread())
			.subscribe(new Subscriber<TAppBfrjJtcyb>(){

				@Override
				public void onCompleted() {
					// TODO Auto-generated method stub
				}

				@Override
				public void onError(Throwable arg0) {
					// TODO Auto-generated method stub
				}

				@Override
				public void onNext(TAppBfrjJtcyb arg0) {
					// TODO Auto-generated method stub
					mTAppBfrjJtcybView.getjtcyXxUuid(arg0);
				}
				
			});
       }

	public void deljtcyxx(TAppBfrjJtcyb mAppBfrjJtcyb){
		mTAppBfrjJtcybModel.deletejtcy(mAppBfrjJtcyb)
				.subscribeOn(Schedulers.io())
				.unsubscribeOn(Schedulers.io())
				.observeOn(AndroidSchedulers.mainThread())
				.subscribe(new Subscriber<String>(){

					@Override
					public void onCompleted() {
						// TODO Auto-generated method stub
					}

					@Override
					public void onError(Throwable arg0) {
						// TODO Auto-generated method stub
					}

					@Override
					public void onNext(String arg0) {
						// TODO Auto-generated method stub
						if(arg0.equals("1")){
							mTAppBfrjJtcybView.deleteSuccess(mAppBfrjJtcyb);
						}else{
							mTAppBfrjJtcybView.deletefalse(arg0);
						}
					}

				});
	}
}
